package algotithm.leetcode.dp.hot.test62;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/9-18:43
 * @Title 62.不同路径
 * @URL https://leetcode-cn.com/problems/unique-paths/
 */
public class Solution {

    public static void main(String[] args) {
        int m = 3;
        int n = 7;
        Solution solution = new Solution();
        int res = solution.uniquePaths(m,n);
        System.out.println(res);
    }

    public int uniquePaths(int m, int n) {
        int[][] dp = new int[m][n];
        for (int i = 0; i < m; i++) {
            dp[i][0] = 1;
        }
        for (int j = 0; j < n; j++) {
            dp[0][j] = 1;
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
            }
        }
        return dp[m-1][n-1];
    }
}
// 这个属于数学思想了，一共需要向下走 (m-1) + (n-1) = (m+n-2)步，其中任选向下的(m-1)或者向上的(n-1)步就行
//class Solution {
//    public int uniquePaths(int m, int n) {
//        long ans = 1;
//        for (int x = n, y = 1; y < m; ++x,++y) {
//            ans = ans * x / y;
//        }
//        return (int)ans;
//    }
//}